package com.xy.controller.mainData;

import com.xy.api.model.dto.mainData.ContactDTO;
import com.xy.api.model.request.mainData.ContactRequest;
import com.xy.api.model.response.R;
import com.xy.api.model.response.Rows;
import com.xy.api.service.mainData.IContactService;
import com.xy.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/contact")
public class ContactController extends BaseController {

    @Autowired
    private IContactService contactService;

    @PostMapping("/queryList")
    public R queryContactList(@RequestBody ContactRequest request) {
        Rows<ContactDTO> rows = contactService.queryContactList(request);
        return success(rows);
    }

    @PostMapping("/detail")
    public R<ContactDTO> contactDetail(@RequestBody ContactRequest request) {
        ContactDTO contact = contactService.contactDetail(request.getId());
        return success(contact);
    }

    @PostMapping("/edit")
    public R<ContactDTO> editContact(@RequestBody ContactDTO request) {
        contactService.editContact(request);
        return success();
    }

    @PostMapping("/delete")
    public R deleteContact(@RequestBody ContactRequest request) {
        contactService.deleteContact(request.getId());
        return success();
    }
}
